using System.Collections.Generic;
using System.Runtime.Serialization;
using Common;
using ImageProcessing.Common;
using ImageProcessing.Engine;

namespace WcfService.DataContracts
{
    [DataContract]
    public class LookupPointsResponse
    {
        public bool ImageFound { get { return BestFoundObject != null; } }

        [DataMember]
        public FoundObjectInfo BestFoundObject;

        [DataMember]
        public List<FoundObjectInfo> AllFoundObjects;

        public LookupPointsResponse(PointsResultProcessor result)
        {
            AllFoundObjects = new List<FoundObjectInfo>();
            BestFoundObject = new FoundObjectInfo(result.BestFoundObject);
            foreach (var foundObject in result.AllFoundObjects)
            {
                AllFoundObjects.Add(new FoundObjectInfo(foundObject));
            }
        }

        public LookupPointsResponse() { }
    }

    [DataContract]
    public class FoundObjectInfo
    {

        [DataMember] 
        public TagInfo TagInfo;
        
        [DataMember]
        public List<PointInfo> FoundPoints;

        [DataMember]
        public float Confidence;

        public FoundObjectInfo(FoundObject foundObject)
        {
            TagInfo = foundObject.TagInfo;
            Confidence = foundObject.Confidence;
            FoundPoints = new List<PointInfo>();

            foreach (InterestPoint interestPoint in foundObject.FoundPoints)
            {
                FoundPoints.Add(interestPoint.PointInfo);
            }
        }
    }
}